﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Application = System.Windows.Application;

namespace Wpf1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        [DllImport("User32")]
        private static extern IntPtr GetDesktopWindow();

        [DllImport("User32")]
        private static extern IntPtr GetWindowDC(IntPtr hwnd);

        [DllImport("User32")]
        private static extern IntPtr GetForegroundWindow();

        [DllImport("GDI32")]
        private static extern UInt64 BitBlt(
            IntPtr dstDc, int xDst, int yDst, int width, int height,
            IntPtr srcDc, int xSrc, int ySrc, int rop);

        static void CopyScreen(int x, int y, int width, int height)
        {
            try
            {
                var bmp = new Bitmap(width, height);
                var g = Graphics.FromImage(bmp);
                var dc1 = g.GetHdc();
                var dc2 = GetWindowDC(GetForegroundWindow());
                BitBlt(dc1, x, y, width, height, dc2, x, y, 13369376);
                g.ReleaseHdc(dc1);
            }
            catch (Exception)
            {
                
            }
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            if (e.Args.Count() > 0)
            {
                Current.StartupUri = new Uri("MainWindow.xaml",UriKind.RelativeOrAbsolute);
                return;
            }
            ConsoleHelper.Show();
            Console.SetWindowSize(80, 24);
            Console.SetWindowPosition(0,0);
            Console.Title = @"WPF Console DEMO";
            var b = Screen.PrimaryScreen.Bounds;
            
            while (true)
            {
                var command = Console.ReadLine();
                if (string.IsNullOrEmpty(command)) continue;
                if (command == "exit") break;
                switch (command)
                {
                    case "s":
                        //var src = BitmapSource.Create(b.Width, b.Height, 96, 96, PixelFormats.Bgr32,)
                        break;
                }
            }
            Current.Shutdown();
        }
    }
}
